package face.pay.common.enterprise.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import face.pay.common.enterprise.service.IMchAgencyInfoService;
import face.pay.common.enterprise.service.ITerminalTargetDayCountService;
import face.pay.constant.UserType;
import face.pay.dao.MchAgencyInfoDao;
import face.pay.dao.TerminalTargetDayCountDao;
import face.pay.entity.MchAgencyInfo;
import face.pay.entity.TerminalTargetDayCount;
import face.pay.entity.UserInfo;
import face.pay.util.DateUtil;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Classname TerminalTargetCountServiceImpl
 * @Description JJL
 * @Date 2019/10/23 13:07
 */
@Service
@Slf4j
public class TerminalTargetDayCountServiceImpl implements ITerminalTargetDayCountService {

    @Autowired
    private TerminalTargetDayCountDao targetCountDao;

    @Override
    public PageData queryTargetList(UserInfo loginUser, String mchUserName,PageParam pageParam, String startTime, String endTime) {

        PageHelper.startPage(pageParam.getPageNo(), pageParam.getPageSize());

        String userType = loginUser.getType();
        List<TerminalTargetDayCount> targetList = new ArrayList<>();

        if(UserType.ENTERPRISE.equals(userType)){
            targetList = targetCountDao.queryMchTerTargets(loginUser.getId(),loginUser.getOemId(),startTime,endTime);
        }else {
            targetList = targetCountDao.queryUserTargets(loginUser.getId(),loginUser.getOemId(),mchUserName,startTime,endTime);

        }
        PageInfo<TerminalTargetDayCount> pageInfo = new PageInfo<>(targetList);

        PageData<TerminalTargetDayCount> pageData = new PageData<>(pageInfo.getTotal(), targetList);

        return pageData;

    }

    /**
     * 查询当日明细
     *
     * @param loginUser
     * @param pageParam
     * @param mchUserName
     * @return
     */
    @Override
    public PageData queryToDayList(UserInfo loginUser, PageParam pageParam, String mchUserName) {
        PageHelper.startPage(pageParam.getPageNo(), pageParam.getPageSize());

        String userType = loginUser.getType();
        List<TerminalTargetDayCount> targetList = new ArrayList<>();

        if(UserType.ENTERPRISE.equals(userType)){
            targetList = targetCountDao.queryToDayMchTerTargets(loginUser.getId());
        }else {
            targetList = targetCountDao.queryToDayUserTargets(loginUser.getId(),mchUserName);
        }
        PageInfo<TerminalTargetDayCount> pageInfo = new PageInfo<>(targetList);

        PageData<TerminalTargetDayCount> pageData = new PageData<>(pageInfo.getTotal(), targetList);

        return pageData;
    }


}
